import { StudentInfo, StudentQueryKeyWord, StudentScore, AddStudentInfo, StudentList, classList } from './model/studentModel';

import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';

enum Api {
    GetScore = '/student/score',
    QueryAllStudent = '/student/query',
    GetOneStudent = '/student/get',
    Add = '/student/add',
    Update = '/student/update',
    Delete = '/student/delete',
    getAllClass = '/class/all'
}

/**
 * @description: 获取指定学生成绩
 */
export function getScore(params: { id: string }, mode: ErrorMessageMode = 'modal') {
    return defHttp.get<StudentScore>(
        {
            url: Api.GetScore,
            params,
        },
        {
            errorMessageMode: mode,
            isQuChengGatewayUnifyFormat: false,
        },
    );
}

/**
 * @description: 查询全部学生
 */
export function queryStudent(params: StudentQueryKeyWord, mode: ErrorMessageMode = 'modal') {
    return defHttp.post<StudentList>(
        {
            url: Api.QueryAllStudent,
            params,
        },
        {
            errorMessageMode: mode,
            //使用mock或测试地址时，可通过设置apiUrl使用.env中配置的VITE_PROXY不同别名
            // apiUrl: '/demo-api',
            //使用mock或测试接口时，如返回的直接为数据，不包含渠成网关中统一定义的code和msg，可通过设置isQuChengGatewayUnifyFormat为false
            isQuChengGatewayUnifyFormat: false,
            //可选参数
            // joinParamsToUrl: true,
            // joinTime: false,
        },
    );
}


/**
 * @description: 新增学生
 */
export function addStudent(params: AddStudentInfo, mode: ErrorMessageMode = 'modal') {
    return defHttp.post<string>(
        {
            url: Api.Add,
            params,
        },
        {
            errorMessageMode: mode,
            isQuChengGatewayUnifyFormat: false,
        },
    );
}
/**
 * @description: 修改学生
 */
export function updateStudent(params: StudentInfo, mode: ErrorMessageMode = 'modal') {
    return defHttp.put<string>(
        {
            url: Api.Update,
            params,
        },
        {
            errorMessageMode: mode,
            isQuChengGatewayUnifyFormat: false,
        },
    );
}
/**
 * @description: 获取指定学生信息
 */
export function getStudent(params: { id: number }, mode: ErrorMessageMode = 'modal') {
    return defHttp.get<StudentInfo>(
        {
            url: Api.GetOneStudent,
            params,
        },
        {
            errorMessageMode: mode,
            isQuChengGatewayUnifyFormat: false,
        },
    );
}
/**
 * @description: 删除学生
 */
export function deleteStudent(id: number, mode: ErrorMessageMode = 'modal') {
    return defHttp.delete<string>(
        {
            //采用url传参需要指定joinParamsToUrl为true
            url: Api.Delete + '?no=' + id,
        },
        {
            errorMessageMode: mode,
            isQuChengGatewayUnifyFormat: false,
        },
    );
}

export function queryAllClass(params: { id: string }, mode: ErrorMessageMode = 'modal') {
    return defHttp.get<classList>(
        {
            url: Api.getAllClass,
            params
        },
        {
            errorMessageMode: mode,
            //使用mock或测试地址时，可通过设置apiUrl使用.env中配置的VITE_PROXY不同别名
            // apiUrl: '/demo-api',
            //使用mock或测试接口时，如返回的直接为数据，不包含渠成网关中统一定义的code和msg，可通过设置isQuChengGatewayUnifyFormat为false
            isQuChengGatewayUnifyFormat: false,
            //可选参数
            // joinParamsToUrl: true,
            // joinTime: false,
        },
    );
}